<template>
	<TinyForm ref="refTinyForm" v-bind="$attrs" v-on="$listeners" :schema="searchSchema" />
</template>

<script>
import TinyForm from './TinyForm.vue';

export default {
	name: "TinySearch",
	components: {
		TinyForm
	},
	props: {
		/**
		 * @description 表单数据
		 * @type {Array}
		 * @required true
		 */
		schema: {
			type: Array,
			default: () => []
		},
		/**
		 * @description 查询事件
		 * @type {Function}
		 * @default () => {}
		 */
		handler: {
			type: Function,
			default: () => {}
		}
	},
	computed: {
		searchSchema({schema}) {
			return [
					...schema,
					{
						slots: (h, ...p) => {
							return h('div', [
								h('t-button', {
									props: {
										type: 'primary'
									},
									on: {
										click: () => {
											this.$emit('search')
										}
									}
								}, '查询'),
								h('t-button', {
									on: {
										click: () => {
											this.$refs.refTinyForm.reset()
											this.$emit('search')
										}
									}
								}, '重置'),
								this.handler && this.handler(h, ...p)
							])
						}
					}
				]
		}
	}
}
</script>